package com.example.base.Action;
import java.util.List;

import com.example.base.ResultVO;
import org.springframework.web.servlet.ModelAndView;

public class BaseAction {

	public ResultVO success(String string) {

		return new ResultVO(string, true);
	}

	public ResultVO error(String string) {

		return new ResultVO(string, false);
	}

	public ResultVO success(List<?> list) {

		return new ResultVO(true, list);
	}

	public ResultVO success(Object object) {

		return new ResultVO(true, object);
	}

	public ResultVO success(Object object, String string) {

		return new ResultVO(true, object, string);
	}

	public ResultVO success(List<?> list, String string) {

		return new ResultVO(true,list, string);
	}

//	public void validate(Object entity, BindingResult bindingResult) {
//
//		if (bindingResult.hasErrors()) {
//			ObjectError objectError = bindingResult.getAllErrors().get(0);
//			throw new ValidateException(objectError.getDefaultMessage());
//		}
//	}

	/**
	 * 统一返回视图模型
	 * @param view 跳转视图
	 * @param name	属性名
	 * @param value 属性值
	 * @return 视图模型
	 */
	public ModelAndView view(String view, String name, Object value){
		ModelAndView modelAndView = new ModelAndView(view);
		modelAndView.addObject(name, value);
		return modelAndView;
	}

	/**
	 * 统一返回视图模型
	 * @param view 跳转视图
	 * @return 视图模型
	 */
	public ModelAndView view(String view){
		ModelAndView modelAndView = new ModelAndView(view);
		return modelAndView;
	}
}
